package com.frx.leetoffer;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IDEA
 *
 * @author: xrf
 * @Date: 2019/10/31
 * @Time: 16:16
 */
public class SubSetTest {

    public static void main(String[] args){
        int[] arr = {1,2,3,4};
        String a = "0.999999";
        BigDecimal bigDecimal = new BigDecimal(a);

        System.out.println(bigDecimal);
        Double b = Double.valueOf(a);
        System.out.println(b);
        String c = String.format("%.3f",b);
        System.out.println(c);
        selectSub(arr);
    }

    public static void selectSub(int[] arr){
        List<List<Integer>> lists = new ArrayList<>();
        lists.add(new ArrayList<>());
        int n = (int) Math.pow(2,arr.length);
        for (int i=1;i<n;i++){
            lists.add(subList(arr,i));
        }
        System.out.println(lists);
    }
    public static List<Integer> subList(int[] arr,int a){
        List<Integer> list = new ArrayList<>();
        StringBuffer str = new StringBuffer(Integer.toBinaryString(a));
        for (int j=str.length();j<arr.length;j++){
            str.insert(0,"0");
        }
        System.out.println(str.toString());
        char[] chars = str.toString().toCharArray();
        for (int i=0;i<chars.length;i++){
            if (chars[i]  == '1'){
                list.add(arr[i]);
            }
        }
        return list;
    }


}
